<?php
class Bids_model extends MY_Model
{
	public
		$table = 'users_bids'
		//$prKey = 'users_id',
		//$publishedField = 'faq_status',

	;

	function __construct()
	{
		parent::__construct();

		$this->fields = array(
			'bid_ID'            => T_('Bid No'),
			'bid_date'          => T_('Bid Date'),
			'bid_user_ID'       => T_('Member ID'),
			'bid_response'      => T_('Response Excerpt'),
			'bid_price' 	    => T_('Bid'),
		);

		$this->rules = array(
			
		);
	}

    function search() {

       $userID = $this->auth->getID();
       $sql = "SELECT * FROM user_bids
               WHERE ub_user_ID='".$userID."'";

       $result = $this->db->query($sql)->result_array();
       $this->data['referrals'] = $result;

    }
    function insert($data)
	{
		if (!empty($data))
		{
			parent::insert($data);

			if ($this->db->insert_id() > 0)
			{
				$this->log->writeMessage('done', T_('Bid was added succesfully.'));

				return TRUE;
			}
			else
			{
				$this->log->writeMessage('error', T_('Error! Bid was not created.'));

				return FALSE;
			}
		}
	}

    function getByReferral($referral){
       $userID = $this->auth->getID();
       $sql = "SELECT * FROM users_bids";//!!!!change
       $result = $this->db->query($sql)->result_array();
       return $result;
    }

    function countBids($referral){
       $userID = $this->auth->getID();

       $sql = "SELECT COUNT(*) AS number
				FROM ".$this->table;
       $result = $this->db->query($sql)->row_array();

       return $result['number'];
    }
    function searchBid($bid){
       $sql = "SELECT * FROM ".$this->table."
               WHERE ub_ID=".$bid." LIMIT 1";//ub_user_ID='".$userID."' AND
       $result = $this->db->query($sql)->row_array();
       return $result;
	}
}
?>